/**
 * 双指针滑动窗口
 * @param {number} target
 * @param {number[]} nums
 * @return {number}
 */

const minSubArrayLen = (target, nums) => {
  const len = nums.length
  let l = r = 0, sum = 0, res = Infinity

  while (r < len) {
    sum += nums[r]
    while (sum >= target) {
      res = res < r - l ? res : r - l
      sum -= nums[l++];
    }
    r++
  }

  return res === Infinity ? 0 : res + 1
}

console.log(minSubArrayLen(80, [10, 5, 13, 4, 8, 4, 5, 11, 14, 9, 16, 10, 20, 8]))